/*
 * @Author: your name
 * @Date: 2021-11-09 20:01:21
 * @LastEditTime: 2021-11-09 20:03:09
 * @LastEditors: your name
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \li-yuwei\egg-example\app\core\base_controller.js
 */
"use strict";

const Controller = require("egg").Controller;
class UserController extends Controller {
    async success(data) {
        // affectedRows 编辑 更新 删除
        // 获取  get select
        if (data.affectedRows !== undefined) {
            // 操作结果
            if (data.affectedRows >= 1) {
                this.ctx.body = {
                    success: true,
                    message: "操作成功",
                    code: 200,
                };
            } else {
                this.ctx.body = {
                    success: false,
                    message: "操作失败",
                    code: 400,
                };
            }
        } else {
            // 返回数据
            this.ctx.body = {
                success: true,
                data,
                code: 200,
            };
        }
    }
    async error(message = "请求失败") {
        this.ctx.body = {
            success: false,
            message,
            code: 401,
        };
    }
}

module.exports = UserController;